#include "RingQueue.hpp"
#include <pthread.h>
#include <unistd.h>
#include <ctime>

using namespace RingQueueModule;

void *Consumer(void *args)
{
    RingQueue<int> *ring_queue = static_cast<RingQueue<int> *>(args);
    while(true)
    {
        sleep(1);

        int data;
        ring_queue->Pop(&data);
        std::cout << "消费了一个数据: " << data << std::endl;
    }
}

int pdata = 0;
void *Productor(void *args)
{
    RingQueue<int> *ring_queue = static_cast<RingQueue<int> *>(args);
    
    while (true)
    {

        ring_queue->Equeue(pdata);
        //std::cout << "生产了一个数据: " << pdata << std::endl;
        pdata++;
    }
}

int main()
{
    RingQueue<int> *ring_queue = new RingQueue<int>(5); 
    
    pthread_t c1, p1, c2,c3,p2;
    pthread_create(&c1, nullptr, Consumer, ring_queue);
    pthread_create(&c2, nullptr, Consumer, ring_queue);
    pthread_create(&c3, nullptr, Consumer, ring_queue);
    pthread_create(&p1, nullptr, Productor, ring_queue);
    pthread_create(&p2, nullptr, Productor, ring_queue);


    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(c3, nullptr);
    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);


    delete ring_queue;

    return 0;
}